import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-edit',
  templateUrl: './edit.component.html',
  styleUrls: ['./edit.component.css']
})
export class EditComponent implements OnInit {
  public info: any = {
    value: '',
    radioValue: '0',
    checkOptionsOne: [
      { label: 'Apple', value: 'Apple', checked: true },
      { label: 'Pear', value: 'Pear' },
      { label: 'Orange', value: 'Orange' }
    ],
    data: '',
    selectedValue: '',
    editorContent: '',
  };
  public file: any;
  constructor() { }
  log(value: object[]): void {
    console.log(value);
  }
  onChange(result: Date): void {
    console.log('onChange: ', result);
  }
  getTime(data: Date){
    const y = data.getFullYear();
    //console.log(y);
    const m = data.getMonth()+1;
    //console.log(m);
    const d = data.getDate();
    //console.log(d);
    return `${y}-${m}-${d}`;
  }
  ngOnInit() {
    this.getTime(new Date());
  }
  dosubmit(){
    console.log(this.info);
  }
  changeImg(e) {
    console.log(e.target.files[0]);
    if(!e.target.files){
      return ;
    }
    this.file = e.target.files[0];
    var reader = new FileReader();
    reader.readAsDataURL(this.file);
    reader.onload = function(){
      var dataUrl = reader.result;
      // 转化成base64
      console.log(dataUrl);
    }
  }
}
